/**Filename: blockedList.c
 * Author(s): Vladimir Dudnic, Michael Groenier, Derek Fleener
 * Winter 2013 TCSS422
 * Project 2
 */

#include"blockedList.h"

int blockedList_init(blockedList* the_blockedList, int the_size){
  int rv = 0;
  the_blockedList->al = (arrayList*)malloc(sizeof(arrayList));
  rv = init_list(the_blockedList->al, the_size);

  the_blockedList->lock = (pthread_mutex_t*)malloc(sizeof(pthread_mutex_t));
  pthread_mutex_init(the_blockedList->lock, NULL);

  return rv;
}
void* blockedList_remove(blockedList* the_blockedList, int the_index){
  void* item;
  pthread_mutex_lock(the_blockedList->lock);
  item = list_remove(the_blockedList->al, the_index);
  pthread_mutex_unlock(the_blockedList->lock);
  return item;
}

void* blockedList_get(blockedList* the_blockedList, int the_index){
  void* item;
  pthread_mutex_lock(the_blockedList->lock);
  item = list_get(the_blockedList->al, the_index);
  pthread_mutex_unlock(the_blockedList->lock);
  return item;
}

int blockedList_add(blockedList* the_blockedList, void* the_item){
  int rv = 0;
  pthread_mutex_lock(the_blockedList->lock);
  rv = list_add(the_blockedList->al, the_item);
  pthread_mutex_unlock(the_blockedList->lock);
  return rv;
}
void blockedList_destroy(blockedList* the_blockedList){
  pthread_mutex_lock(the_blockedList->lock);
  list_destroy(the_blockedList->al);
  pthread_mutex_unlock(the_blockedList->lock);
}
